"""
#!!===========================================================
#版权（C）2023, Huawei Technologies Co., HUTAF xDevice
#!!===========================================================
#文 件 名:      SecurityUserIamPinAuthApi.py
#文件说明:      pin相关公共AW
#作   者:
#生成日期:
#!!===========================================================
"""

# -*- coding: utf-8 -*-
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import keyword

@keyword
def PinAuth(oh_device, pin, pin_type=0):
    """
    #======================================================================
    #   @Method:           PinAuth(oh_device, pin,pin_type)
    #   @Precondition:
    #   @Func:             口令认证
    #   @Param:            pin：设置的PIN码
    #   @Param:            pin_type: 0：6位数字密码,1：自定义数字密码,2：混合密码。默认值为0
    #   @Example:
    #======================================================================
    """
    if pin_type == 0:
        CommonOH.touchByText(oh_device, text=pin[0])
        CommonOH.touchByText(oh_device, text=pin[1])
        CommonOH.touchByText(oh_device, text=pin[2])
        CommonOH.touchByText(oh_device, text=pin[3])
        CommonOH.touchByText(oh_device, text=pin[4])
        CommonOH.touchByText(oh_device, text=pin[5])
    elif pin_type == 1:
        CommonOH.inputTextByType(oh_device, "TextInput", pin, 5)
        CommonOH.touchByText(oh_device, "确定")
    elif pin_type == 2:
        CommonOH.inputTextByType(oh_device, "TextInput", pin)
        CommonOH.touchByText(oh_device, "确定")
    else:
        print("您输入的type错误，请输入正确的type值")
        return False


@keyword
def CancelAuth(oh_device, windowmode=1):
    """
    #======================================================================
    #   @Method:           CancelAuth(oh_device)
    #   @Precondition:
    #   @Func:             口令认证取消
    #   @Param:
    #   @Example:
    #======================================================================
    """
    if windowmode == 1:
        CommonOH.touchByText(oh_device, "取消")
    elif windowmode == 2:
        CommonOH.touchByText(oh_device, "返回")
    else:
        print("您输入的windowmode错误，请输入正确的windowmode值")

